<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/animate.js"></script>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        img {
            vertical-align: top;
        }

        .swiper {
            width: 1226px;
            margin: 50px auto;
            position: relative;
            /* overflow: hidden; */
        }

        .swiper-wrapper {
            width: 400%;
            display: flex;
            position: relative;
        }

        .swiper-wrapper .slider-item {
            width: 25%;
        }

        .swiper-wrapper .show {
            display: block;
        }

        .swiper-wrapper .slider-item img {
            width: 100%;
        }

        .navbar {
            position: absolute;
            right: 50px;
            bottom: 20px;
            display: flex;

        }

        .navbar li {
            width: 10px;
            height: 10px;
            margin: 0 5px;
            border-radius: 50%;
            border: 1px solid #999999;
            background-color: rgba(0, 0, 0, 0.2);
        }

        .navbar .active {
            background-color: #fff;
        }
    </style>
</head>

<body>
    <!-- .swiper>.swiper-wrapper>.slider-item*4>img[src=../images/2.webp] -->
    <div class="swiper">
        <div class="swiper-wrapper">
            <div class="slider-item"><img src="../images/1.jpg" alt=""></div>
            <div class="slider-item"><img src="../images/2.webp" alt=""></div>
            <div class="slider-item"><img src="../images/3.webp" alt=""></div>
            <div class="slider-item"><img src="../images/4.webp" alt=""></div>
        </div>
        <ul class="navbar">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
</body>
<script>

    // 轮播的功能
    // 1. 点击切换
    // 2. 自动切换
    // 3. 移入暂停 移出启动

    var swiper = document.getElementsByClassName("swiper")[0];
    var swiperWrapper = document.getElementsByClassName("swiper-wrapper")[0];
    var swiperSlideItems = document.getElementsByClassName("slider-item");
    var navBar = document.getElementsByClassName("nav")[0];
    var dotList = document.getElementsByTagName("li");

    var swiperWidth = swiper.clientWidth; // 一张图片的宽度

    var timer = null; // 全局变量 记录轮播的编号(方便后续清除)
    var index = 0;   // 全局变量 记录轮播的下标(方便下次轮播切换)


    // 点击切换 => 点击对应的导航,切换到对应的图片
    // 1. 导航和图片的下标也是一一对应的
    // 2. 向左滚动的图片张数 刚好 和下标对应
    for(let i=0;i<dotList.length;i++){
        let dot = dotList[i];
        dot.onclick = function(){
            console.log(this,i);

            // 导航切换
            for(var j=0;j<dotList.length;j++){
                dotList[j].className = "";
            }
            dotList[i].className = "active";

            // 图片滚动
            animate(swiperWrapper,"left", -swiperWidth * i,"ease-out");

        }
    }
   




</script>

</html>